package br.com.danilloguimaraes.web.beans;

import java.io.Serializable;
import java.util.Locale;
import javax.enterprise.context.SessionScoped;
import javax.faces.context.FacesContext;
import javax.inject.Named;

/**
 *
 * @author danillo
 */
@Named(value = "beanSession")
@SessionScoped
public class BeanSession implements Serializable {

    private String value;
    
    /**
     * Creates a new instance of BeanSession
     */
    public BeanSession() {
        System.out.println("nova sessao");
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
        System.out.println(value);
    }
    
    public String getLocale(){
        StringBuilder sb = new StringBuilder();
        Locale l = FacesContext.getCurrentInstance().getViewRoot().getLocale();
        sb.append(l.getLanguage()).append("_").append(l.getCountry());
        return sb.toString();
    }
    
    public void setLocale(String value){
        String[] values = value.split("_");
        FacesContext.getCurrentInstance().
                getViewRoot().setLocale(new Locale(values[0].toLowerCase(), 
                    values[1].toUpperCase()));
    }
    
    public void printValue(){
        System.out.println(value);
    }
}
